
package com.beerq.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;

import com.beerq.R;


public class ShareDialog extends Dialog {
    private View mSharePopWindowView;

    public ShareDialog(Context context) {
        super(context, R.style.AppTheme);
        setCustomView(context);
    }

    public void setCustomView(Context context) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mSharePopWindowView = inflater.inflate(R.layout.share_popwindow_view, null);


//        mSharePopWindowView.setOnTouchListener(new OnTouchListener() {
//
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//                int top = mSharePopWindowView.findViewById(R.id.share_popwindow).getTop();
//                int bottom = mSharePopWindowView.findViewById(R.id.share_popwindow).getBottom();
//                int y = (int) event.getY();
//                if (event.getAction() == MotionEvent.ACTION_UP) {
//                    if (y < top || y > bottom) {
//                        dismiss();
//                    }
//                }
//                return true;
//            }
//        });

//        Window window = getWindow();
//        WindowManager.LayoutParams windowParams = new WindowManager.LayoutParams();
//        int[] wh = getDeviceWH(context);
//        windowParams.x = 0;
//        windowParams.y = wh[1];
//        windowParams.width=wh[0];
//        windowParams.gravity= Gravity.BOTTOM;
//        // 控制dialog停放位置
//        window.setAttributes(windowParams);
//        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
//        setCanceledOnTouchOutside(true);
        super.setContentView(mSharePopWindowView, new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));
    }

    // 终端设备的WH
    public static int[] getDeviceWH(Context context) {
        int[] wh = new int[2];
        int w = 0;
        int h = 0;
        DisplayMetrics dm = new DisplayMetrics();
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getMetrics(dm);
        w = dm.widthPixels;
        h = dm.heightPixels;
        wh[0] = w;
        wh[1] = h;
        return wh;
    }





}
